<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/9
 * Time: 10:14
 */

namespace backend\controllers;

use backend\models\Basedrawals;
use backend\models\Basemodule;
use backend\models\Baseorders;
use backend\models\Baseprivilege;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii;

class AccountController extends CommonController
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => [
                            'get-nodes',
                            'information',
                            'ajax-chart',
                            'finance-list',
                            'cash-list',
                            'bonus-examine',
                        ],
                        'allow' => true,
                    ],
                    [
                        'actions' => ['logout', 'index','get-nodes'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }


    public function actionIndex()
    {
        return $this->render('index');
    }

    /**
     * @return array
     * 获取角色下侧边栏
     */
    public function actionGetNodes()
    {
        if (yii::$app->request->isPost){
            $privilege = new Baseprivilege();
            $nodes = $privilege->getModules($this->roleId, $this->userId);
            return $this->renderJson(['Children' => $nodes]);
        }

    }

    /**
     * @return string
     * 初始化首页数据
     */
    public function actionInformation()
    {
        //成交订单数量
        $volume = 0;
        //上线玩家
        $online_user = 10;
        //在线玩家
        $onlogin_game_user = 20;
        $onlogin_ting_user = 30;
        //新增玩家
        $add_user = 40;
        //平台服务费
        $servicefee = 500;
        //玩家消耗钻石总计
        $diamond = 600;
        //真人玩家输赢金币
        $machine = 700;
        $data = [
            'onlogin_game_user' => $onlogin_game_user,
            'onlogin_ting_user' => $onlogin_ting_user,
            'volume' => $volume,
            'online_user' => $online_user,
            'add_user' => $add_user,
            'servicefee' => $servicefee,
            'diamond' => $diamond,
            'machine' => $machine
        ];
        return $this->renderPartial('information', $data);
    }

    /**
     * @return array
     * 底部chart图表数据展示
     */
    public function actionAjaxChart()
    {
        $startDate = yii::$app->request->get('startDate');
        $finishDate = yii::$app->request->get('finishDate');
        $moneymodify = new RecordCurrencyChange();
        $playInfo = $moneymodify->getChartData($startDate,$finishDate);
        return $this->renderJson($playInfo);
    }

    /**
     * @return array|string
     * 收益统计
     */
    public function actionFinanceList()
    {
        $moduleId = yii::$app->request->get('moduleId');
        $module = Basemodule::findOne(['Id' => $moduleId]);
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            $pageCurrent = $post['pageCurrent'];
            $pageSize = $post['pageSize'];
            $draw = new Baseorders();
            $datas = $draw->getFinanceListData($post, $pageCurrent, $pageSize);
            return $this->renderJson($datas);
        }
        $citem = Basemodule::getMoreRole($this->roleId, $moduleId);
        $data = [
            'module' => $module,
            'citem' => $citem
        ];
        return $this->renderPartial('finance-list', $data);
    }


    public function actionStatistics()
    {
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            $order = new Basedrawals();
            $data = $order->getTotal($post);
            return $this->renderJson($data);
        }
        return $this->renderJson(['statusCode' => 300, 'message'=>'非法操作']);
    }


    /**
     * @return array|string
     * @throws yii\db\Exception
     * 提现记录
     */
    public function actionCashList()
    {
        $moduleId = yii::$app->request->get('moduleId');
        $module = Basemodule::findOne(['Id' => $moduleId]);
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            $pageCurrent = $post['pageCurrent'];
            $pageSize = $post['pageSize'];
            $draw = new Baseorders();
            $datas = $draw->getCashListData($post, $pageCurrent, $pageSize);
            return $this->renderJson($datas);
        }
        $citem = Basemodule::getMoreRole($this->roleId, $moduleId);
        $data = [
            'module' => $module,
            'citem' => $citem
        ];
        return $this->renderPartial('cash-list', $data);
    }


    /**
     * @return array|string
     * 提点明细
     */
    public function actionBonusExamine()
    {
        $moduleId = yii::$app->request->get('moduleId');
        $module = Basemodule::findOne(['Id' => $moduleId]);
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            $pageCurrent = $post['pageCurrent'];
            $pageSize = $post['pageSize'];
            $bonus = new Baseorders();
            $datas = $bonus->getBonusListData($post, $pageCurrent, $pageSize);
            return $this->renderJson($datas);
        }
        $citem = Basemodule::getMoreRole($this->roleId, $moduleId);
        $data = [
            'module' => $module,
            'citem' => $citem
        ];
        return $this->renderPartial('bonus-examine', $data);
    }


}